Newer
Older
pixi.js / examples / example 2 / index.html
@Mat Groves Mat Groves on 24 Feb 2013 1 KB Documentation first draft

<!DOCTYPE HTML>
<html>
<head>
	<title>pixi.js example 1</title>
	<style>
		body {
			margin: 0;
			padding: 0;
			background-color: #000000;
		}
	</style>
	<script src="pixi.js"></script>
</head>
<body>
	<script>
	
	// create a new loader
	var imagesToLoad = [ "img/stretched_hyper_tile.jpg"];
	
	loader = new PIXI.AssetLoader(imagesToLoad);
	
	loader.onComplete = onAssetsLoaded
	
	loader.load();
	
	function onAssetsLoaded()
	{
		// create an new instance of a pixi stage
		var stage = new PIXI.Stage(0x66FF99);
		
		// create a renderer instance.
		var renderer = PIXI.autoDetectRenderer(400, 300);
		
		// add the renderer view element to the DOM
		document.body.appendChild(renderer.view);
		
		requestAnimFrame( animate );
		
		// create a new Sprite using an image path..
		var bunny = PIXI.Sprite.fromImage("bunny.png");
		
		// center the sprites anchor point
		bunny.anchor.x = 0.5;
		bunny.anchor.y = 0.5;
		
		// move the sprite t the center of the screen
		bunny.position.x = 200;
		bunny.position.y = 150;
		
		stage.addChild(bunny);
	}
	
	function animate() {
	
	    requestAnimFrame( animate );
	
	    // just for fun, lets rotate mr rabbit a little
	    bunny.rotation += 0.1;
		
	    // render the stage   
	    renderer.render(stage);
	}

	</script>

	</body>
</html>